import { RouteRecordRaw } from 'vue-router';

import Login from '@/views/Login.vue';
import Layout from '@/components/Layout.vue';

const routes: Array<RouteRecordRaw> = [
  {
    path: '',
    redirect: (_) => {
      return { path: '/system' };
    }
  },

  {
    path: '/login',
    name: 'login',
    meta: {
      white: true
    },
    component: Login
  },

  {
    path: '/system',
    name: 'System',
    meta: {
      base: true
    },
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: '/dashboard',
        name: 'Dashboard',
        meta: {
          base: true
        },
        component: () => import('@/views/Dashboard/index.vue')
      },
      {
        path: '/personal',
        name: 'Personal',
        meta: {
          base: true
        },
        component: () => import('@/views/Personal.vue')
      }
    ]
  },

  {
    path: '/setting',
    name: 'Setting',
    component: Layout,
    redirect: '/role_list',
    children: [
      {
        path: '/account_list',
        name: 'account_list',
        component: () => import('@/views/setting/account/index.vue')
      },
      {
        path: '/role_list',
        name: 'role_list',
        component: () => import('@/views/setting/role/index.vue')
      },
      {
        path: '/permission_list',
        name: 'permission_list',
        component: () => import('@/views/setting/permission/index.vue')
      },
      {
        path: '/repair_database',
        name: 'repair_database',
        component: () => import('@/views/setting/repair/index.vue')
      }
    ]
  },

  {
    path: '/management',
    name: 'Management',
    component: Layout,
    redirect: '/user_list',
    children: [
      // 会员列表
      {
        path: '/user_list',
        name: 'user_list',
        component: () => import('@/views/user/index.vue')
      },
      // 商品列表
      {
        path: '/goods_list/:name',
        name: 'Goods List',
        component: () => import('@/views/goods/index.vue')
      },
      // 商品分类
      {
        path: '/goods_category',
        name: 'Goods Category',
        component: () => import('@/views/GoodsCategory/index.vue')
      },
      // 商品规格
      {
        path: '/goods_specs',
        name: 'Goods Specs',
        component: () => import('@/views/GoodsSpecs/index.vue')
      },
      // 订单列表
      {
        path: '/order_list',
        name: 'order_list',
        component: () => import('@/views/order/index.vue')
      },
      // 售后订单列表
      {
        path: '/appeal_list',
        name: 'appeal_list',
        component: () => import('@/views/appeal/index.vue')
      },
      // 轮播图列表
      {
        path: '/banner_list',
        name: 'banner_list',
        component: () => import('@/views/banner/index.vue')
      },
      // 公告列表
      {
        path: '/notify_list',
        name: 'notify_list',
        component: () => import('@/views/notify/index.vue')
      },
      // 快捷导航列表
      {
        path: '/quick_list',
        name: 'quick_list',
        component: () => import('@/views/quick/index.vue')
      },
      // 积分明细
      {
        path: '/credits_list',
        name: 'credits_list',
        component: () => import('@/views/UserCredits/index.vue')
      },
      // 佣金明细
      {
        path: '/bonus_list',
        name: 'bonus_list',
        component: () => import('@/views/UserBonus/index.vue')
      },
      // 充值记录
      {
        path: '/recharge_list',
        name: 'recharge_list',
        component: () => import('@/views/UserRecharge/index.vue')
      },
      // 提现记录
      {
        path: '/capital_list',
        name: 'capital_list',
        component: () => import('@/views/UserCapital/index.vue')
      },
      // 提现手续
      {
        path: '/capital_config',
        name: 'capital_config',
        component: () => import('@/views/UserCapitalConfig/index.vue')
      },
      // 计划任务
      {
        path: '/task_config',
        name: 'task_config',
        component: () => import('@/views/TaskConfig/index.vue')
      }
    ]
  },

  {
    path: '/error',
    name: 'Error',
    meta: {
      white: true
    },
    component: Layout,
    redirect: '/404',
    children: [
      {
        path: '/404',
        name: '404',
        meta: {
          white: true
        },
        component: () => import('@/views/Error/notfound.vue')
      }
    ]
  },
  {
    path: '/:currentPath(.*)*', // 路由未匹配到，进入这个
    redirect: (_) => {
      return { path: '/404' };
      // return { path: '/login' }
    }
  }
];

export default routes;
